package models

import (
	"github.com/cy77cc/hioshop/global"
)

type Product struct {
	Model
	GoodsId               uint    `json:"goods_id"`
	GoodsSpecificationIds string  `json:"goods_specification_ids"`
	GoodsSn               string  `json:"goods_sn"`
	GoodsNumber           uint    `json:"goods_number"`
	RetailPrice           float64 `json:"retail_price"`
	Cost                  float64 `json:"cost"`
	GoodsWeight           float32 `json:"goods_weight"`
	HasChange             int8    `json:"has_change"`
	GoodsName             string  `json:"goods_name"`
	IsOnSale              int8    `json:"is_on_sale"`
	IsDelete              int8    `json:"is_delete"`
}

func (p *Product) GetProductList() (list []Product, err error) {
	err = global.DB.Model(p).Where("goods_id", p.GoodsId).Find(&list).Error
	return
}

func (p *Product) GetProductById() error {
	return global.DB.Model(&Product{}).Where("is_delete=0 and id=?", p.ID).Find(p).Error
}
